﻿using HuiZe.education.Common;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace HuiZe.education.Resource.Controls
{
    /// <summary>
    /// PageManager.xaml 的交互逻辑
    /// </summary>
    public partial class myBookEdit2 : UserControl
    {

        public string NomalImage { get; set; }
        public string Labtext { get; set; }
        public string Id { get; set; }
        public bool IsSelectd { get; set; } = false;
        public myBookEdit2()
        {
            InitializeComponent();
            Loaded += PageManager_Loaded;
        }
        private void PageManager_Loaded(object sender, RoutedEventArgs e)
        {
            Image image = new Image(); 
            image.Source = new BitmapImage(new Uri(NomalImage, UriKind.Absolute));
            image.Stretch = Stretch.Fill;
            BookImg.Source = image.Source;
            BookName.Content = Labtext;
        }

         private  void RadioButton_Click(object sender, RoutedEventArgs e)
        {
            CustomRadioButton customRadioButton = sender as CustomRadioButton;
            //CurrentIndex = customRadioButton.Index;
        }

        private void UserControl_FocusableChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
        }

        private void UserControl_KeyDown(object sender, KeyEventArgs e)
        {

        }

        private void BookImg_MouseDown(object sender, MouseButtonEventArgs e)
        {
          
            var WrapParent = this.Parent as WrapPanel;
            foreach (var control in WrapParent.Children)
            {
                if (control == this)
                {
                    if (ImgBorder.BorderBrush == Brushes.Red)
                    {
                        ImgBorder.BorderBrush = Brushes.Gray;
                        CommonMethods.MySpaceSelectedId.Remove(Id.ToString());
                        IsSelectd = true;
                    }
                    else
                    {
                        if (CommonMethods.MySpaceSelectedId == null)
                        {
                            CommonMethods.MySpaceSelectedId = new System.Collections.Generic.List<string>();
                        }
                        ImgBorder.BorderBrush = Brushes.Red;
                        CommonMethods.MySpaceSelectedId.Add(Id.ToString());
                        IsSelectd = false ;
                    }
                }
                else
                {
                }

            }

        }
    }
}
